<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>service-details</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../../css/global.css">
		<link rel="stylesheet" href="../../../../css/style.css">
		<link rel="stylesheet" href="../../../../css/mui.picker.css">
		<link rel="stylesheet" href="../../../../css/mui.poppicker.css">
		<style type="text/css">
			.mui-btn-block{
				border: 0;
				font-size: 16px;
				color: #a9a9a9;
			}
			.mui-pciker-list li {
				width: 99%;
			    display: block;
			    line-height: 18px;
			    white-space: normal;
				font-size: 14px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">Hot Account Report</h1>
		</header>
		<div class="mui-content">
			<div class="details_con">
				<div hidden>
					<input type="hidden" id="id" />
					<input type="hidden" id="helpId" />
				</div>
				<div class="clum" style="height: auto;overflow: auto;">
					<div class="name" style="width: 100%;">Hot Account Type<em class="t_red">*</em></div>
					<div class="txt" style="height: auto;overflow: auto;width: 100%;">
						<input type="hidden" id="hotAccountType"/>
						<button id='hotAccountTypeName' class="mui-btn mui-btn-block mui-btn-select" type='button' mulitline="true" style="margin-bottom: 0;height: auto;text-align: left;overflow : auto; white-space: normal;">请选择</button>
					</div>
				</div>
				<div class="clum">
					<span class="name">Fail Type<em class="t_red">*</em></span>
					<span class="txt">
						<input type="hidden" id="failType"/>
						<button id='failTypeName' class="mui-btn mui-btn-block mui-btn-select" type='button'>请选择</button>
					</span>
				</div>
				<div class="clum" style="height: auto;overflow: auto;">
					<div class="name" style="width: 100%;">Severity Level<em class="t_red">*</em></div>
					<div class="txt" style="height: auto;overflow: auto;width: 100%;">
						<input type="hidden" id="severityLevel"/>
						<button id='severityLevelName' class="mui-btn mui-btn-block mui-btn-select" type='button' mulitline="true" style="margin-bottom: 0;height: auto;text-align: left;overflow : auto; white-space: normal;">请选择</button>
					</div>
				</div>
				<div class="clum">
					<span class="name">Instrument Status<em class="t_red">*</em></span>
					<span class="txt">
						<button id='instrunmentStatus' class="mui-btn mui-btn-block mui-btn-select" type='button'>请选择</button>
					</span>
				</div>
				<div class="clum">
					<span class="name">Start Date</span>
					<button id='startDate'  type="button" class="selectDate">请选择时间</button>
				</div>
				<div class="clum">
					<span class="name">End Date</span>
					<button id='endDate'  type="button" class="selectDate">请选择时间</button>
				</div>
				<div class="clum nobor autoHeight">
					<span class="name">Problem<em class="t_red">*</em></span>
					<textarea class="textarea" maxlength="1000" id="problem" style="margin-bottom: 0;"></textarea> 
				</div>
				<div class="clum nobor autoHeight">
					<span class="name">Work done(incldue Date)<em class="t_red">*</em></span>
					<textarea class="textarea" maxlength="1000" id="workDone" style="margin-bottom: 0;"></textarea> 
				</div>
				<div class="clum">
					<span class="name">Equipment Model</span>
					<span class="txt">
						<button id='equipmentMode' class="mui-btn mui-btn-block mui-btn-select" type='button'>请选择</button>
					</span>
				</div>
				<div class="clum">
					<span class="name">Serial No</span>
					<input type="text" maxlength="50" id="serialNo" class="d_ipt" style="padding: 0;"/>
				</div>
				<div class="my-content-cell"  id="partsList">
					<div class="inline-block">
						<em>备件列表</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<!-- <div class="my-content-cell" id="addParts">
					<div class="inline-block">
						<em>添加备件</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div> -->
				
			</div>
			<div class="btn_box">
				<button class="fl"  id="saveBtn">保存草稿</button>
				<button class="fr red" id="submitBtn">正式提交</button>
			</div>
			<div style="height: 50px;"></div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../../js/mui.min.js"></script>
		<script src="../../../../js/utils/h.js"></script>
		<script src="../../../../js/constant.js"></script>
		<script src="../../../../js/utils/base64.js"></script>
		<script src="../../../../js/common.js"></script>
		<script src="../../../../js/utils/md5.js"></script>
		<script src="../../../../js/utils/sortMap.js"></script>
		<script src="../../../../js/utils/http.js"></script>
		<script src="../../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../../js/utils/rolldate.min.js"></script>
		<script src="../../../../js/mui.picker.js"></script>
		<script src="../../../../js/mui.poppicker.js"></script>
		<script type="text/javascript" charset="utf-8">
			var serviceNo
			var helpId
			var planId
			var noticeId
			var id
			var divBu
			
			// 提交状态 0未提交 1已提交
			var submitStatus = 0;
			/*
			* 禁止交互事件
			*/
			function noInteraction() {
				if(submitStatus && submitStatus == '1') {
					h('#hotAccountTypeName').attr('disabled', 'disabled')
					h('#failTypeName').attr('disabled', 'disabled')
					h('#severityLevelName').attr('disabled', 'disabled')
					h('#instrunmentStatus').attr('disabled', 'disabled')
					h('#startDate').attr('disabled', 'disabled')
					h('#endDate').attr('disabled', 'disabled')
					h('#problem').attr('readonly', 'readonly')
					h('#workDone').attr('readonly', 'readonly')
					h('#equipmentMode').attr('disabled', 'disabled')
					h('#serialNo').attr('readonly', 'readonly')
					h('#addParts').hide()
					h('#saveBtn').hide()
					h('#submitBtn').hide()
				}
			}
			
			(function($, doc) {
				
				$.init();
		
				$.plusReady(function() {
					initClick()
					initDateTimeControls()
					 
					var self = plus.webview.currentWebview();
					submitStatus = self.submitStatus
					serviceNo = self.serviceNo
					divBu = self.divBu
					h('#id').val(self.hotId)
					id = self.hotId
					app.showWaiting()
					noInteraction()
					ajaxGet(BASE_URL + "cc/hot/account/report/detailHoatAccountReport", {
						id: self.hotId
					}, function(data) {
						app.closeWaiting()
						if (data.code === 200) {
							h('#hotAccountType').val(data.data.hotAccountType)
							h('#hotAccountTypeName').html(data.data.hotAccountTypeName || '请选择')
							h('#failType').val(data.data.failType)
							h('#failTypeName').html(data.data.failTypeName || '请选择')
							h('#severityLevel').val(data.data.severityLevel)
							h('#severityLevelName').html(data.data.severityLevelName || '请选择')
							// h('#instrunmentStatus').html(data.data.instrunmentStatus || '请选择')
							h('#instrunmentStatus').attr('data-val',data.data.instrunmentStatus)
							h('#startDate').html(data.data.startDate || '请选择时间')
							h('#endDate').html(data.data.endDate || '请选择时间')
							h('#problem').val(data.data.problem)
							h('#workDone').val(data.data.workDone)
							
							// h('#equipmentMode').html(data.data.equipmentMode || '请选择')
							h('#equipmentMode').attr('data-val',data.data.equipmentMode)
							h('#serialNo').val(data.data.serialNo)
							helpId = data.data.helpId
							planId = data.data.planId
							noticeId = data.data.noticeId

							ajaxGetJson(BASE_URL + 'cc/dict/selectCCInstrumentStatus', {
								engineerId: app.getUser().enginnerId
							}, function(resp) {
								resp.forEach(function (item) {
									if (item.value == data.data.instrunmentStatus){
										h('#instrunmentStatus').html(item.text || '请选择')
									}
								})
							});
							ajaxGetJson(BASE_URL + 'cc/dict/selectCCEquipmentModel', {
								engineerId: app.getUser().enginnerId
							}, function(resp) {
								resp.forEach(function (item) {
									if (item.value == data.data.equipmentMode){
										h('#equipmentMode').html(item.text || '请选择')
									}
								})
							});

						} else {
							app.toast(data.msg)
						}
						noInteraction()
					}, function(errorMsg) {
						noInteraction()
						app.closeWaiting()
						app.toast(errorMsg)
					});
					//备件列表
					h('#partsList').tap(function() {
						app.jumpTo('/view/service/report/errorhot/sparePartsList.html','view/service/report/errorhot/sparePartsList.html',{
							serviceNo:serviceNo,
							helpId:helpId,
							portType: 4,
							submitStatus: submitStatus
						})
					})
					//添加备件
					h('#addParts').tap(function() {
						app.jumpTo('/view/service/report/errorhot/sparePartsAdd.html','view/service/report/errorhot/sparePartsAdd.html',{
							serviceNo:serviceNo,
							helpId:helpId,
							portType: 4
						})
					})
					
					// 保存按钮触发事件
					h('#saveBtn').tap(function() {
						h(this).attr('disabled','disabled');
						app.hideSoftKeybord()
						updateHotData('正在保存...', function(data) {
							if (data.code === 200) {
								id = data.data.id
								app.toast("保存成功")
								// 查找需要跳转的页面，并指定刷新的方法
								var erroOrHot = plus.webview.getWebviewById('view/service/report/errorhot/erroOrHot.html');
								if (erroOrHot) {
									erroOrHot.close()
								}
								mui.back();
							} else {
								h('#saveBtn').removeAttr('disabled');
								h('#submitBtn').removeAttr('disabled');
								app.toast(data.msg)
							}
						})
					})
					
					// 提交
					h('#submitBtn').tap(function() {
						h(this).attr('disabled','disabled');
						app.hideSoftKeybord()
						updateHotData('正在提交...', function(data) {
							console.log(JSON.stringify(data))
							if (data.code === 200) {
								id = data.data.id
								hotAccountTypeSubmit()
							} else {
								h('#saveBtn').removeAttr('disabled');
								h('#submitBtn').removeAttr('disabled');
								app.closeWaiting()
								app.toast(data.msg)
							}
						})
					})
				});
			}(mui, document));
			
			function hotAccountTypeSubmit() {
				var enginnerId = app.getUser().enginnerId
				ajaxGet(BASE_URL + 'cc/hot/account/report/hoatAccountReportSubmit', {
					id: id,
					enginnerId: enginnerId
				}, function(data){
					app.closeWaiting()
					if (data.code === 200) {
						app.toast("提交成功")
						// 查找需要跳转的页面，并指定刷新的方法
						var erroOrHot = plus.webview.getWebviewById('view/service/report/errorhot/erroOrHot.html');
						if (erroOrHot) {
							erroOrHot.close()
						}
						mui.back();
					} else {
						h('#saveBtn').removeAttr('disabled');
						h('#submitBtn').removeAttr('disabled');
						app.toast(data.msg)
					}
					
					
				}, function(errorMsg){
					h('#saveBtn').removeAttr('disabled');
					h('#submitBtn').removeAttr('disabled');
					app.closeWaiting()
					app.toast(errorMsg)
				});
			}
			
			function updateHotData(tips, callBack) {
				
				var hotAccountTypeName = h('#hotAccountTypeName').html()
				var hotAccountType = h('#hotAccountType').val()
				if (!hotAccountTypeName || hotAccountTypeName == "请选择") {
					h('#saveBtn').removeAttr('disabled');
					h('#submitBtn').removeAttr('disabled');
					app.toast('请选择Hot Account Type')
					return
				}
				
				var failTypeName = h('#failTypeName').html()
				var failType = h('#failType').val()
				if (!failTypeName || failTypeName == "请选择") {
					h('#saveBtn').removeAttr('disabled');
					h('#submitBtn').removeAttr('disabled');
					app.toast('请选择Fail Type')
					return
				}
				
				var severityLevelName = h('#severityLevelName').html()
				var severityLevel = h('#severityLevel').val()
				if (!severityLevelName || severityLevelName == "请选择") {
					h('#saveBtn').removeAttr('disabled');
					h('#submitBtn').removeAttr('disabled');
					app.toast('请选择Severity Level')
					return
				}
				
				var instrunmentStatus = h('#instrunmentStatus').attr('data-val')
				if (!instrunmentStatus || instrunmentStatus == "请选择") {
					h('#saveBtn').removeAttr('disabled');
					h('#submitBtn').removeAttr('disabled');
					app.toast('请选择Instrument Status')
					return
				}
				
				var equipmentMode = h('#equipmentMode').attr('data-val')
				if (!equipmentMode || equipmentMode == "请选择") {
					equipmentMode = "";
				}
				
				var startDate = h('#startDate').html()
				if (!startDate || startDate == "请选择时间") {
					startDate = "";
				}
				
				var endDate = h('#endDate').html();
				if (!endDate || endDate == "请选择时间") {
					endDate = "";
				}
				
				if (startDate && endDate) {
					if (stringYYYYMMDDHHMMToDate(startDate).getTime() > stringYYYYMMDDHHMMToDate(endDate).getTime()) {
						h('#saveBtn').removeAttr('disabled');
						h('#submitBtn').removeAttr('disabled');
						app.toast('Start Date不能大于End Date')
						return false
					}
				}
				
				var problem = h('#problem').val()
				if (!problem) {
					h('#saveBtn').removeAttr('disabled');
					h('#submitBtn').removeAttr('disabled');
					app.toast('请输入Problem')
					return
				}
				var workDone = h('#workDone').val()
				if (!workDone) {
					h('#saveBtn').removeAttr('disabled');
					h('#submitBtn').removeAttr('disabled');
					app.toast('请输入Work done(incldue Date)')
					return
				}
				
				var enginnerId = app.getUser().enginnerId
				var fseName = app.getUser().name;
				var params = {
					id: id,
					hotAccountType: hotAccountType,
					hotAccountTypeName: hotAccountTypeName,
					failType: failType,
					failTypeName: failTypeName,
					severityLevel: severityLevel,
					severityLevelName: severityLevelName,
					instrunmentStatus: instrunmentStatus,
					startDate: startDate,
					endDate: endDate,
					problem: h('#problem').val(),
					workDone: h('#workDone').val(),
					equipmentMode : equipmentMode,
					serialNo : h('#serialNo').val(),
					planId : planId,
					noticeId : noticeId,
					enginnerId : enginnerId,
					fseName: fseName,
					serviceNo : serviceNo,
					helpId: helpId
				}
				if (!app.getNetworkState()) {
					h('#saveBtn').removeAttr('disabled');
					h('#submitBtn').removeAttr('disabled');
					app.closeWaiting()
					app.toast("无网络")
					return
				}
				app.showWaiting(tips)
				ajaxPost(BASE_URL + 'cc/hot/account/report/updateHoatAccountReport', params, function(data) {
					app.closeWaiting()
					callBack(data)
				}, function(err) {
					h('#saveBtn').removeAttr('disabled');
					h('#submitBtn').removeAttr('disabled');
					app.closeWaiting()
					app.toast(err)
				})
			}
			
			function initClick() {
				// hotAccountType
				h('#hotAccountTypeName').tap(function() {
					app.hideSoftKeybord()
					app.showWaiting()
					var userPicker = new mui.PopPicker();
					ajaxGetJson(BASE_URL + 'cc/dict/selectHotAccountType', {
						engineerId: app.getUser().enginnerId
					}, function(data) {
						app.closeWaiting()
						console.log(JSON.stringify(data))
						if (!data || data.length <= 0) {
							app.toast("无Hot Account Type数据")
							return
						}
						userPicker.setData(data);
						userPicker.show(function(items) {
							h('#hotAccountTypeName').html(items[0].text)
							h('#hotAccountType').val(items[0].value)
							userPicker.dispose()
						});
					});
				})
				
				// failType
				h('#failTypeName').tap(function() {
					app.hideSoftKeybord()
					app.showWaiting()
					var userPicker = new mui.PopPicker();
					ajaxGetJson(BASE_URL + 'cc/dict/selectCCFailtype', {
						engineerId: app.getUser().enginnerId
					}, function(data) {
						app.closeWaiting()
						console.log(JSON.stringify(data))
						if (!data || data.length <= 0) {
							app.toast("无Fail Type数据")
							return
						}
						var typeData
						if(divBu.indexOf('CMD')!= -1){
							typeData = data;
						} else {
							typeData = data.splice(0,5);
						}
						
						userPicker.setData(typeData);
						userPicker.show(function(items) {
							h('#failTypeName').html(items[0].text)
							h('#failType').val(items[0].value)
							userPicker.dispose()
						});
					});
				})
				
				
				// severityLevel
				h('#severityLevelName').tap(function() {
					app.hideSoftKeybord()
					app.showWaiting()
					var userPicker = new mui.PopPicker();
					ajaxGetJson(BASE_URL + 'cc/dict/selectCCHTSeverity', {
						engineerId: app.getUser().enginnerId
					}, function(data) {
						app.closeWaiting()
						console.log(JSON.stringify(data))
						if (!data || data.length <= 0) {
							app.toast("无Severity Level数据")
							return
						}
						userPicker.setData(data);
						userPicker.show(function(items) {
							h('#severityLevelName').html(items[0].text)
							h('#severityLevel').val(items[0].value)
							userPicker.dispose()
						});
					});
				})
				
				// instrunmentStatus
				h('#instrunmentStatus').tap(function() {
					app.hideSoftKeybord()
					app.showWaiting()
					var userPicker = new mui.PopPicker();
					ajaxGetJson(BASE_URL + 'cc/dict/selectCCInstrumentStatus', {
						engineerId: app.getUser().enginnerId
					}, function(data) {
						app.closeWaiting()
						console.log(JSON.stringify(data))
						if (!data || data.length <= 0) {
							app.toast("无Instrunment Status数据")
							return
						}
						userPicker.setData(data);
						userPicker.show(function(items) {
							h('#instrunmentStatus').html(items[0].text)
							h('#instrunmentStatus').attr('data-val',items[0].value)
							userPicker.dispose()
						});
					});
				})
				
				// equipmentMode
				h('#equipmentMode').tap(function() {
					app.hideSoftKeybord()
					app.showWaiting()
					var userPicker = new mui.PopPicker();
					ajaxGetJson(BASE_URL + 'cc/dict/selectCCEquipmentModel', {
						engineerId: app.getUser().enginnerId
					}, function(data) {
						app.closeWaiting()
						console.log(JSON.stringify(data))
						if (!data || data.length <= 0) {
							app.toast("无Equipment Mode数据")
							return
						}
						userPicker.setData(data);
						userPicker.show(function(items) {
							h('#equipmentMode').html(items[0].text)
							h('#equipmentMode').attr('data-val',items[0].value)
							userPicker.dispose()
						});
					});
				})
			}
			
			/**
			 * 初始化日期时间控件
			 */
			function initDateTimeControls() {
				// Error发生时间
				new Rolldate({
					el: '#startDate',
					format: 'YYYY-MM-DD hh:mm',
					beginYear: 2015,
					endYear: 2050,
					trigger: 'click',
					lang: {
						title: '请选择发生日期',
					},
					confirm: function(date) {
						
					}
				})
				
				//跟踪日期
				new Rolldate({
					el: '#endDate',
					format: 'YYYY-MM-DD hh:mm',
					beginYear: 2015,
					endYear: 2050,
					trigger: 'click',
					lang: {
						title: '请选择跟踪日期',
					},
					confirm: function(date) {
						
					}
				})
			}
		</script>
		<!-- js代码 end -->

	</body>

</html>
